package freecomm.study.notificationtest2;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DisplayActivity extends Activity
{
    private Button cancelBtn;
    private Notification n;
    private NotificationManager nm;
    private static final int ID = 1;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display_activitiy);
        Log.i("test", "shit2");
        cancelBtn = (Button) findViewById(R.id.button1);
        String service = NOTIFICATION_SERVICE;
        nm = (NotificationManager) getSystemService(service);
        n = new Notification();
        int icon = n.icon = R.drawable.ic_launcher;
        String tickerText = "Test Notification";
        long when = System.currentTimeMillis();
        n.icon = icon;
        n.tickerText = tickerText;
        n.when = when;

        n.defaults |= Notification.DEFAULT_VIBRATE;
        long[] vibrate = { 1000, 1000, 1000, 1000,1000,1000,1000 };
        n.vibrate = vibrate;
        n.defaults |= Notification.DEFAULT_LIGHTS;
        n.ledARGB = Color.RED;
        n.ledOnMS = 0;
        n.ledOffMS = 1;
        n.flags |= Notification.FLAG_SHOW_LIGHTS;
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
        n.setLatestEventInfo(this, "My Title", "My Content", pi);
        nm.notify(ID, n);
        cancelBtn.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                nm.cancel(ID);
            }
        });
    }
}
